package com.bcu.cn.onlineexamsystem.user.controller;

import com.bcu.cn.onlineexamsystem.user.entity.Student;
import com.bcu.cn.onlineexamsystem.user.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import jakarta.servlet.http.HttpSession;

@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    // 学生成绩查询
    @GetMapping("/score")
    public String viewScore(HttpSession session, Model model) {
        Student user = (Student) session.getAttribute("user");
        if (user == null || !"student".equals(user.getRole())) {
            return "redirect:/student/login";
        }
        model.addAttribute("user", user);
        return "student/score";
    }

    // 学生排名查询
    @GetMapping("/ranking")
    public String viewRanking(HttpSession session, Model model) {
        Student user = (Student) session.getAttribute("user");
        if (user == null || !"student".equals(user.getRole())) {
            return "redirect:/student/login";
        }
        model.addAttribute("user", user);
        return "student/ranking";
    }
}
